//
// Created by denglibin on 2021/4/11 0011.
//

#include "spirit.h"
#include "stdlib.h"
#include "SDL_image.h"
#include "stdio.h"
Spirit* SP_crateSpirit(const char* imgPath,GameWindow * gameWindow){
    Spirit * spirit = (Spirit*)calloc(1, sizeof(Spirit));
    spirit->speed = 2;
    SDL_Surface  * surface = IMG_Load(imgPath);
    if (surface == NULL){
        SDL_Log("Can not load image %s\n", SDL_GetError());
        exit(1);
    }
    SDL_Texture * imgTexture = SDL_CreateTextureFromSurface(gameWindow->sdl_win_renderer, surface);
    if (imgTexture == NULL){
        SDL_Log("Can not create texture %s\n", SDL_GetError());
        exit(1);
    }
    SDL_FreeSurface(surface);//清理
    SDL_QueryTexture(imgTexture, NULL, NULL, &(spirit->w), &(spirit->h));
    spirit->pTexture = imgTexture;
    return spirit;
}

void SP_freeSpirit(Spirit* spirit){

    free(spirit);
}